/**
 * Copyright ©2003~2019年3月31日 szkingdom
 * @author raohj
 * @date 2019年3月31日
 * @file RF5.java
 * @comment : please input your comment to this file
 * @version : input version
 * @modify:
 * 		1、 2019年3月31日 由 raohj 新建文件
 */
package com.ccnu.demojava.f5;

import java.io.IOException;
import java.net.Socket;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author raohj
 * @date 2019年3月31日
 * @version 
 * @comment to add your comment
 */
public class RF5 {
	/**
	 * @author raohj
	 * @date 2019年3月31日
	 * @version 
	 * @comment 服务器对象
	 */
	public static class SERVER{
		String ip;
		int port;
		
		/**
		 * @param ip
		 * @param port
		 */
		public SERVER(String ip, int port) {
			super();
			this.ip = ip;
			this.port = port;
		}
		public String getIp() {
			return ip;
		}
		public void setIp(String ip) {
			this.ip = ip;
		}
		public int getPort() {
			return port;
		}
		public void setPort(int port) {
			this.port = port;
		}
	}
	
    public static class RThreadPoolRunnable implements Runnable{
        public void run() {
        	try {
            	Socket s1 = new Socket("192.168.0.11", 8000);
				s1.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	
        	try {
            	Socket s1 = new Socket("192.168.0.11", 6001);
				s1.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        	
        	try {
            	Socket s1 = new Socket("192.168.0.11", 2000);
				s1.close();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
        }
    }

    public static class RThreadPoolExceptionRunnable implements Runnable{
        private static int i=0;
        public void run() {
            i++;
            if(i%3==0){
                @SuppressWarnings("unused")
				int j=i/0;
            }
            System.out.println("[" + Thread.currentThread().threadId() + "]" + "Runnable Hello world![" + i + "]");
        }
    }

    // 测试线程池
    public static void testFixedPool1(){
        ExecutorService saleTicketsPool = Executors.newFixedThreadPool(1);
        while(true) {
            saleTicketsPool.execute(new Runnable() {
                public void run() {
                	try {
                    	Socket s1 = new Socket("192.168.0.11", 8000);
        				s1.close();
        			} catch (IOException e) {
        				// TODO Auto-generated catch block
        				e.printStackTrace();
        			}
                	
                	try {
						Thread.sleep(5000);
					} catch (InterruptedException e2) {
						// TODO Auto-generated catch block
						e2.printStackTrace();
					}
                	try {
                    	Socket s1 = new Socket("192.168.0.11", 6001);
        				s1.close();
        			} catch (IOException e) {
        				// TODO Auto-generated catch block
        				e.printStackTrace();
        			}
                	try {
						Thread.sleep(5000);
					} catch (InterruptedException e1) {
						// TODO Auto-generated catch block
						e1.printStackTrace();
					}
                	try {
                    	Socket s1 = new Socket("192.168.0.11", 2000);
        				s1.close();
        			} catch (IOException e) {
        				// TODO Auto-generated catch block
        				e.printStackTrace();
        			}
                }
            });
        }
    }
	
	/**
	 * @author raohj
	 * @date 2019年3月31日
	 * @comment 模拟F5进行探测
	 * @param 
	 * @return 
	 */
	public static void F5() {
		testFixedPool1();
	}
}
